package com.wzx.clusterserver.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/user")
public class UserController {

    @GetMapping("login")
    public String login(Model model, HttpServletRequest request) {
        model.addAttribute("sessionId", request.getSession().getId());
        model.addAttribute("port", request.getLocalPort());
        return "login";
    }

    @ResponseBody
    @GetMapping("info")
    public String hello(HttpServletRequest request) {
        return "sessionId: " + request.getSession().getId() +
                "<br/>port: " + request.getLocalPort()  +
                " <h1> 登录成功了 </h1> ";
    }

}
